//
//  YXCache.swift
//  
//
//  Created by tangbl93 on 2021/4/10.
//

import Foundation

@propertyWrapper
public struct YXCacheWrapper<T> {
    private let key: String
    private let defaultValue: T

    public init(key: String, defaultValue: T) {
        self.key = key
        self.defaultValue = defaultValue
    }

    public var wrappedValue: T {
        get {
            return YXGlobalCaching.value(forKey: key) as? T ?? defaultValue
        }
        set {
            YXGlobalCaching.set(newValue, forKey: key)
        }
    }
}
